package com.sphd.emanu.activity.gooddetails;

import android.content.Context;

import com.google.gson.JsonObject;
import com.sphd.emanu.config.Constant;
import com.sphd.emanu.mvp.BasePresenterImpl;
import com.wzutils.BigDisMailUtils;
import com.wzutils.L;

import java.io.IOException;
import java.util.List;

import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class GooddetailsPresenter extends BasePresenterImpl<GooddetailsContract.View> implements GooddetailsContract.Presenter {


    @Override
    public void addOrEditeFood(String name, Integer cateid, MultipartBody.Part bodys, String kg, String price, boolean isDis,
                               boolean isAdded, Integer oid) {

        Call<JsonObject> call =emanuService.addCommodity(name,cateid,bodys, BigDisMailUtils.turn(kg, Constant.POINT),
                BigDisMailUtils.turn(price, Constant.POINT),isDis,isAdded,oid);
        call.enqueue(new Callback<JsonObject>() {
            @Override
            public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                mView.setRes(res(response));
            }

            @Override
            public void onFailure(Call<JsonObject> call, Throwable t) {
                Error(t);
                L.e("error==="+t.getMessage());
            }
        });

    }

    @Override
    public void addCommodityNoImage(String name, Integer cateid, String kg, String price, boolean isDis,
                                    boolean isAdded, Integer oid) {
        Call<JsonObject> call =emanuService.addCommodityNoImage(name,cateid,BigDisMailUtils.turn(kg, Constant.POINT),
                BigDisMailUtils.turn(price, Constant.POINT),isDis,isAdded,oid);
        call.enqueue(new Callback<JsonObject>() {
            @Override
            public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                mView.setRes(res(response));
            }

            @Override
            public void onFailure(Call<JsonObject> call, Throwable t) {
                Error(t);
                L.e("error==="+t.getMessage());
            }
        });
    }

    @Override
    public void updateCommodity(Integer id, String name, Integer cateid, MultipartBody.Part bodys, String kg, String price, boolean isDis,
                                boolean isAdded, Integer oid) {
        Call<JsonObject> call =emanuService.updateCommodity(id,name,cateid,bodys,BigDisMailUtils.turn(kg, Constant.POINT),
                BigDisMailUtils.turn(price, Constant.POINT),isDis,isAdded,oid);

        call.enqueue(new Callback<JsonObject>() {
            @Override
            public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                L.e(response.body().toString());
                mView.setRes(res(response));
            }

            @Override
            public void onFailure(Call<JsonObject> call, Throwable t) {
                Error(t);
                L.e("error==="+t.getMessage());
            }
        });
    }

    @Override
    public void updateCommodityNoImage(Integer id, String name, Integer cateid, String kg, String price, boolean isDis,
                                       boolean isAdded, Integer oid) {
        Call<JsonObject> call = emanuService.updateCommodityNoImage(id, name, cateid, BigDisMailUtils.turn(kg, Constant.POINT),
                BigDisMailUtils.turn(price, Constant.POINT), isDis, isAdded, oid);

        call.enqueue(new Callback<JsonObject>() {
            @Override
            public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                L.e(response.body().toString());
                mView.setRes(res(response));
            }

            @Override
            public void onFailure(Call<JsonObject> call, Throwable t) {
                Error(t);
                L.e("error==="+t.getMessage());
            }
        });

    }



}
